package jxl.readXls;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import jxl.Cell;
import jxl.JxlUtil;
import jxl.Sheet;
import jxl.Workbook;

public class ImportXlsData {

	/** 读取的xls文件名 **/
	private static final String XLS_FILE_NAME = "C:/任务数据.xls";
	/** 默认的工作表 **/
	private static final int DEFAULT_SHEET = 0;

	/** 开始的行 **/
	private static final int START_ROW = 2;
	/** 结束的行 **/
	private static final int END_ROW = 86;
	/** 开始的列 **/
	private static final int START_COLUMN = 1;
	/** 结束的列 **/
	private static final int END_COLUMN = 9;

	public static void main(String[] args) {
		List<Task> taskList=new ArrayList<Task>();
		Workbook book = null;
		Cell cell = null;
		String content = null;
		Task task = null;
		try {
			book = Workbook.getWorkbook(new File(XLS_FILE_NAME));
			Sheet sheet = book.getSheet(DEFAULT_SHEET); // 获得第一个工作表对象
			for (int i = START_ROW - 1; i < END_ROW; i++) {
				task = new Task();
				for (int j = START_COLUMN - 1; j < END_COLUMN; j++) {
					cell = sheet.getCell(j,i);
					content = cell.getContents().trim();
					switch (j) {
					case 0:
						task.setTaskId(Integer.valueOf(content));
						break;
					case 1:
						task.setTaskName(content);
						break;
					case 2:
						if (content.equals("剧情任务")) {
							task.setTaskSpecies(1);
						} else if (content.equals("支线任务")) {
							task.setTaskSpecies(2);
						} else if (content.equals("日常任务")) {
							task.setTaskSpecies(3);
						}
						break;
					case 3:
						task.setTaskType(Integer.valueOf(content));
						break;
					case 4:
						task.setTaskCode(content);
						break;
					case 5:
						task.setTaskRequire(content);
						break;
					case 6:
						task.setTaskDesc(content);
						break;
					case 7:
						task.setTaskFront(Integer.valueOf(content));
						break;
					case 8:
						task.setTaskJiangli(content);
						break;
					}
				}
				
				taskList.add(task);
			}
			
			SqlMapClientUtil.insertTaskList(taskList);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			JxlUtil.closeQuietly(book);
		}
	}
}
